import unittest
import random

import pytest
from api.GoodsAPI import Goods

class TestAddGoods(unittest.TestCase):

    def setUp(self):
        self.Goods = Goods()

    # 添加商品
    def test_01_post_add_goods(self):
        response = self.Goods.post_add_goods("香蕉"+str(random.randint(100,1000)),"这是香蕉",1,0.1)
        # 断言
        print(response.text)
        self.assertEqual("成功",response.json().get("msg"))

    # 获取商品列表
    def ttest_03_get_goods_list(self):
        response = self.Goods.get_goods_list()
        print(response.json()["data"][0]["id"])
        self.assertEqual("成功", response.json().get("msg"))

    # 编辑商品
    def ttest_02_post_update_goods(self):
        goods_id = self.Goods.get_goods_list().json()["data"][0]["id"]
        goods_name = self.Goods.get_goods_list().json()["data"][0]["name"]
        goods_weight = self.Goods.get_goods_list().json()["data"][0]["weight"]
        goods_price= self.Goods.get_goods_list().json()["data"][0]["price"]
        response = self.Goods.post_update_goods(goods_id,"香蕉","编辑后",goods_weight,0.01)
        # 断言
        print(response.text)
        self.assertEqual("成功",response.json().get("msg"))


if __name__ == '__main__':
    unittest.main()
